package com.example.zg.androidnewview;

import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zg.androidnewview.adapter.BaseAdapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FloatingActionButtonActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_floating_action_button);

        init();


    }

    private void init(){
        data=new ArrayList<>();
        for(int i=1;i<30;i++){
            data.add("item"+i);
        }


        recyclerView=findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(OrientationHelper.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);


        recyclerView.setAdapter(new RecyclerView.Adapter<MViewHolder>() {
            @NonNull
            @Override
            public MViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View inflate = getLayoutInflater().inflate(R.layout.item1, parent, false);

                return new MViewHolder(inflate);
            }

            @Override
            public void onBindViewHolder(@NonNull MViewHolder holder, int position) {
                holder.textView.setText(data.get(position));

            }

            @Override
            public int getItemCount() {
                return data.size();
            }
        });



    }

    class MViewHolder extends ViewHolder{
        public TextView textView;

        public MViewHolder(View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.text_value);
        }

    }




    public void click(View view) {
        Snackbar.make(view,"点击了",Snackbar.LENGTH_INDEFINITE).show();
    }
}
